//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Utils/Texture/Image/ImageConverter.h"
#include "Utils/Base/Meta.Common.h"
#include "Graphics/MetaData/Meta.Sprite.h"

namespace Engine
{
namespace Utils
{

	//
	// Sprite Converter
	//

	class SpriteConverter
	{
	// variables
	protected:
		Ptr< UtilsCore >	_core;


	// metadata
	public:
		struct MetaSpriteAnim
		{
			uint32_array_t	frames;
			uvec2			type;
			uint			rate;
			bool			blend;
			///
			MetaSpriteAnim () : rate(0), blend(false) {}
		};

		struct MetaSprite
		{
			string		image;
			uvec2		frameSize;
			uvec2		frameMargin;
			color4u		color;
			int			newFormat;

			MetaData::BatchMaterialCfg		material;
			MetaData::Sprite2dPhysicsCfg	physics;

			array< MetaSpriteAnim >			animations;
			///
			MetaSprite () : newFormat(EPixelFormat::_UNKNOWN), color(0xFF) {}
		};

		struct MetaSpriteList
		{
			string			inputDir;
			string			outputDir;
			string			extension;
			string_array_t	sprites;
		};

		
		static CMetaClass	metaSpriteAnim;
		static CMetaClass	metaSprite;
		static CMetaClass	metaSpriteList;

		static void InitMetaData ();


	// methods
	public:
		SpriteConverter (UtilsCore *core) : _core(core)
		{
			InitMetaData();
		}
		
		bool LoadConfig (uni_c_string filename, uni_c_string outputPath, bool clearOutputDir);


	private:
		bool _LoadSprite (uni_c_string filename, uni_c_string inputDir, MetaData::Sprite2dCfg &sprite, Image &image);
		bool _SaveSprite (uni_c_string filename, uni_c_string outputDir, const MetaData::Sprite2dCfg &sprite, Image &image);
	};


}	// Utils
}	// Engine